<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="合同状态" prop="oneCategoryId">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option label="请选择" :value="null"></el-option>
          <el-option label="已开启" :value="0"> </el-option>
          <el-option label="已关闭" :value="1"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label-width="40" label="供应商名称" prop="id">
        <el-input
          type="number"
          v-model="queryParams.id"
          placeholder="ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:designator:add']"
          >新增</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="designatorList">
      <el-table-column label="ID" width="55" align="center" prop="id" />
      <el-table-column label="合同编号" align="center" prop="contractNumber" />
      <el-table-column label="合同创建时间" align="center" prop="createTime" />
      <el-table-column label="供应商名称" align="center" prop="supplierName" />
      <el-table-column label="原材料名称" align="center" prop="materialName" />
      <el-table-column label="是否有抵顶物" align="center" prop="BDeduction" />
      <el-table-column
        label="累计结算金额"
        align="center"
        prop="acSettlementAmount"
      />
      <el-table-column
        label="累计应付金额"
        align="center"
        prop="acPayableAmount"
      />
      <el-table-column label="合同状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-switch
            :value="scope.row.status == '0'"
            @change="changeStatus(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column
        width="190px"
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleChangePrice(scope.row)"
            v-hasPermi="['system:designator:remove']"
            >调价</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:designator:edit']"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
  
  <script>
import { listOrders, updateOrders } from "@/api/service/purchase/contract.js";
import NumberFormItem from "@/components/NumberFormItem";
import { listOnInfo } from "@/api/service/info";
export default {
  components: {
    NumberFormItem,
  },
  name: "Designator",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品--主标号表格数据
      designatorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        name: null,
        oneCategoryId: null,
        twoCategoryId: null,
        threeCategoryId: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 开关
    changeStatus(item) {
      const form = { ...item };
      // 改变状态
      form.status = form.status == "0" ? 1 : 0;
      updateOrders(form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        item.status = form.status;
        //this.getList();
      });
    },
    /** 查询产品--主标号列表 */
    getList() {
      this.loading = true;
      listOrders(this.queryParams).then((response) => {
        this.designatorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/purchase/contract/edit",
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push({
        path: `/purchase/contract/edit?id=${row.id}`,
      });
    },
    /** 调价 */
    handleChangePrice(row) {
      this.$router.push({
        path: `/purchase/contract/change-price?id=${row.userId}`,
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/designator/export",
        {
          ...this.queryParams,
        },
        `designator_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.edit-form {
  // display: flex;
  .form-label {
    font-size: 14px;
    font-weight: bold;
    line-height: 36px;
    padding-right: 30px;
    .form-red {
      color: #d23c26;
    }
  }
  .form-value {
    display: flex;
    //gap: 30px;
  }
}

::v-deep .el-tabs__content {
  max-height: 500px;
  overflow: auto;
}

.row-item {
  display: flex;
  // gap: 20px;
}
::v-deep .el-form-item__label {
  // width: 240px;
  text-align: right;
}
.form-right ::v-deep .el-input {
  width: 200px;
}
</style>